#include<iostream>
#include<algorithm>
using namespace std; 
struct segment {
	int begin;
	int end;
};
bool comp(segment x, segment y) {
	if (x.begin == y.begin)
		return x.end < y.end;
	return x.begin < y.begin;
}
int main() {
	int n;
	cin >> n;
	segment a[n];
	for (int i = 0; i < n; i++) {
		cin >> a[i].begin >> a[i].end;
	}
	sort(a, a + n, comp);
	int ended = -1, count = 0, min=10000000,mini=0;
	for (int ik = 0; ik < n; ik++) {
		if (a[ik].begin >= ended) {
			if (a[ik].end < min) {
				min = a[ik].end;
				mini=ik;
				cout << " " << min;
			}
			else{
				ended = min;
				min=10000000;
				count++;
			}
		}
		else{
			ended = min;
			min=10000000;
			count++;
		}
	}
	cout << count;
}
